#include "MenuButton.h"
#include "InputHandler.h"
#include "Defines.h"


MenuButton::MenuButton(const LoadedParams* Params, void (*callback)()) : SDLGameObject(Params), mCallback(callback)
{
	released = false;
	currentFrame = MOUSE_OUT;
}

void MenuButton::Draw()
{
	SDLGameObject::Draw();
}

void MenuButton::Update()
{
	Vector2D* pMousePos = InputHandler::Instance()->getMousePosition();

	if(pMousePos->getX() < (position.getX() + Width) 
	&& pMousePos->getX() > position.getX()
	&& pMousePos->getY() < (position.getY() + Height) 
	&& pMousePos->getY() > position.getY())
	{
		if(InputHandler::Instance()->getMouseButtonState(MOUSE_LEFT) && released)
		{
			currentFrame = CLICKED;
			mCallback();
			released = false;
		}
		else if(!InputHandler::Instance()->getMouseButtonState(MOUSE_LEFT))
		{
			released = true;
			currentFrame = MOUSE_OVER;
		}
	}
	else
	{
	currentFrame = MOUSE_OUT;
	}
}

void MenuButton::Shutdown()
{
	SDLGameObject::Shutdown();
}